package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shkstart
 * @create ${}YEAR-06-08 4:22
 */
@Api(tags = "Blog[文章]")
@RestController
public class ArticleController {


    @Autowired
    private ArticleService articleService;


    @SystemLog(notes = "获取文章列表{前台博客系统}")
    @ApiOperation(value = "获取文章列表接口",notes = "获取文章列表,首页展示单页显示 下拉刷新,只获取公开且未删除文章,默认每页显示个数为10")
    @GetMapping("/articles")
    public ResponseResult getArticles(@RequestParam("current") Integer current)
    {
        return articleService.getArticles(current);
    }


    @SystemLog(notes = "获取文章详情{前台博客系统}")
    @ApiOperation(value = "获取文章详情接口",notes = "根据文章ID 获取文章详细信息,以及 获取上下篇章、相关推荐文章、最新文章")
    @GetMapping("/articles/{articleId}")
    public ResponseResult getArticleDetail(@PathVariable("articleId") Integer articleId)
    {
        return articleService.getArticleDetail(articleId);
    }

    @SystemLog(notes = "搜索文章{前台博客系统}")
    @ApiOperation(value = "搜索文章接口",notes = "根据搜索字段{优先查询文章标题,若没有对应文章标题,则搜索文章内容} 获取相关文章，分页显示 下拉刷新，显示个数默认10")
    @GetMapping("/articles/search")
    public ResponseResult searchArticles(@RequestParam("current") Integer current,
                                         @RequestParam(value = "keywords",required = false) String keywords)
    {
        return articleService.searchArticle(current,keywords);
    }

    @SystemLog(notes = "获取文章分类{前台博客系统}")
    @ApiOperation(value = "获取文章档案接口",notes = "获取文章档案、及相关数据{创建时间、抬头...}")
    @GetMapping("/articles/archives")
    public ResponseResult getArticleArchives(@RequestParam("current") Integer current)
    {
        return articleService.getArticleArchives(current);
    }


    @SystemLog(notes = "获取文章列表{前台博客系统}")
    @ApiOperation(value = "根据条件获取文章列表接口",notes = "根据分类ID 或  根据标签ID 获取文章列表")
    @GetMapping("/articles/condition")
    public ResponseResult getArticlesByCategory(@RequestParam(value = "categoryId",required = false) Integer categoryId,
                                                @RequestParam(value = "tagId",required = false) Integer tagId,
                                                @RequestParam("current") Integer current)
    {
        return articleService.getArticlesByCategory(categoryId,tagId,current);
    }


}
